/*
 * 文件名：BookOrderInfoAction.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：ozm
 * 修改时间：2013-1-29
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.reservation.bookinfo.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.wootide.cms.common.Constants;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.Result;
import com.wootide.cms.common.util.CommonUtil;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.customer.custmanager.pojo.Customer;
import com.wootide.cms.service.facility.room.roominfo.pojo.RoomInfo;
import com.wootide.cms.service.facility.room.roominfo.pojo.RoomPeriod;
import com.wootide.cms.service.facility.room.table.pojo.TableNoInfo;
import com.wootide.cms.service.facility.room.table.pojo.TablePeriod;
import com.wootide.cms.service.reservation.bookinfo.pojo.BookOrderInfo;
import com.wootide.cms.service.reservation.bookinfo.service.BookOrderInfoService;
import com.wootide.cms.sys.common.action.BaseAction;

/**
 * 客户预订控制层
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 * @author ozm
 * @version 2013-1-29
 * @see BookOrderInfoAction
 * @since 2013-1-29下午1:33:34
 */
public class BookOrderInfoAction extends BaseAction implements ServletRequestAware, SessionAware 
{

    /**
     * 意义，目的和功能，以及被用到的地方<br>
     */
    private static final long serialVersionUID = 1L;
    
    //跳转到显示类型
    private static final String SHOWTYPE = "showtype";
    
    private static final String TABLEPERIOD="tableperiod";
    
    //客户预订信息
    private BookOrderInfo bookOrderInfo;
    
    
    
    //日志
    private RunLog runLog;
    
    //客户预订信息系业务层实例
    private BookOrderInfoService bookOrderInfoService;
    
    //分页信息
    private Page page;
    
    //查询条件
    private QueryCondition queryConditon;
    
    // Http请求对象
    private HttpServletRequest request;
    
    // 预订方式结果集
    @SuppressWarnings("rawtypes")
    private List results;
    
    //返回消息
    private String message;
    
    // 是否操作成功
    private Integer actResult = Constants.ACTRESULT_DEF;
    
    // 客户预订ID
    private Integer innerIndex;

    //客户预订集合
    private Integer[] innerIndexs;
    
    //开始时间
    private Timestamp startTime;
    
    //结束时间
    private Timestamp endTime;
    
    //房间类型id
    private Integer roomTypeId;
    
    //房间信息
    private RoomInfo roomInfo;
    
    //桌次信息
    private TableNoInfo tableNoInfo;
    
    //房间号
    private String roomNum;
    
    //桌号
    private String tableNo;
    
    //session
    private Map<String,Object> session;
    
    //预订方式列表
    @SuppressWarnings("rawtypes")
    private List orderByList;
    
    //支付方式列表
    @SuppressWarnings("rawtypes")
    private List paymentMethodsList;
    
    //预订预览房间信息
    @SuppressWarnings("rawtypes")
    private List bookingPreviewRoomsList;
    
    //客户信息
    private Customer customerInfo;
    
  
   

   

    /**
     * 
     * Description:分页查询
     * Implement: <br>
     * @return
     * @see
     * @return String 条转换标识
     * @author ozm2013-1-29下午1:53:19
     */
    public String doQuery()
    {
        try
        {
//            return SUCCESS;
            // 如果从菜单进入，即在没有分页信息的情况下，则默认进入首页
            if (null == page)
            {
                page = new Page();
                page.setCurPage(1);
            }

            // 调用而业务层进行分页查询
            Result result = bookOrderInfoService.queryForPages(page,
                    queryConditon);

            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults) result
                        .getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
                // 获取分页信息
                page = queryResults.getPage();

                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }

        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 
     * Description: 预添加
     * Implement: <br>
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-29下午3:35:20
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String toAdd()
    {
       
        try
        {
//            bookOrderInfo = new BookOrderInfo();
            bookOrderInfo.setDiscount(1.0);
            
            List conditionValueList = new ArrayList();
            Set<Integer> roomPeriodset = (Set<Integer>)(null == session.get("roomPeriod")? null : session.get("roomPeriod"));
            Set<Integer> tablePeriodset = (Set<Integer>)(null == session.get("tablePeriod")? null : session.get("tablePeriod"));
            conditionValueList.add(roomPeriodset);
            conditionValueList.add(tablePeriodset);
            conditionValueList.add(bookOrderInfo);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            // 调用而业务层进行分页查询
            Result result = bookOrderInfoService.queryBookingPreviewInfo(queryConditon);

            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults) result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                //预订方式
                orderByList = (List)queryResults.getResults().get(0);
                //支付方式
                paymentMethodsList = (List)queryResults.getResults().get(1);
                //预订预览房间信息
                bookingPreviewRoomsList = (List)queryResults.getResults().get(2);
                bookOrderInfo = (BookOrderInfo)queryResults.getResults().get(3);
                
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }

        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }

    }
    
  

    /**
     * 
     * Description: 添加可以预订信息
     * Implement: <br>
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-29下午3:37:58
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String doAdd()
    {
        try
        {
           
            //设置订单号
            bookOrderInfo.setOrderNum(CommonUtil.timeToString(null, Constants.TimeFormat.NO_SEPARATOR_MILLISECOND));
            
            runLog.debug("bookOrderInfo=" + bookOrderInfo);

            List conditionValueList = new ArrayList();
            Set<Integer> roomPeriodset = (Set<Integer>)(null == session.get("roomPeriod")? null : session.get("roomPeriod"));
            Set<Integer> tablePeriodset = (Set<Integer>)(null == session.get("tablePeriod")? null : session.get("tablePeriod"));
            conditionValueList.add(roomPeriodset);
            conditionValueList.add(tablePeriodset);
            conditionValueList.add(bookOrderInfo);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            // 调用业务层进行新增操作
            Result result = bookOrderInfoService.addOneBookOrder(queryConditon, request);
            int resultCode = result.getResultCode();
            message = getText(Constants.MESSAGE_PREFIX + resultCode);
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                actResult = Constants.ACTRESULT_SUC;
                clearSession();
                return SUCCESS;
            }
            else
            {
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }

        }
       
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }

    }
    
    
    
    /**
     * 
     * Description: 预修改预订方式信息
     * Implement: <br>
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-29下午3:47:44
     */
    @SuppressWarnings("rawtypes")
    public String toMod()
    {
        try
        {
            runLog.error("toMod");
            innerIndex = innerIndex == null?  bookOrderInfo.getInnerIndex() : innerIndex;
            // 调用业务层获取一个路由对象
            Result result = bookOrderInfoService.viewOneBookOrder(innerIndex);
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults) result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                //预订方式
                orderByList = (List)queryResults.getResults().get(0);
                //支付方式
                paymentMethodsList = (List)queryResults.getResults().get(1);
                //预订预览房间信息
                bookingPreviewRoomsList = (List)queryResults.getResults().get(2);
                bookOrderInfo = (BookOrderInfo)queryResults.getResults().get(3);
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 预修改
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-4-10上午10:31:40
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String toModOrderRoomPeriod()
    {
        try
        {
            runLog.error("toModOrderRoomPeriod");
            List conditionValueList = new ArrayList();
            
            conditionValueList.add(bookOrderInfo.getInnerIndex());
            conditionValueList.add(innerIndex);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            // 调用业务层获取一个路由对象
            Result result = bookOrderInfoService.queryOrderRoomPeriods(queryConditon);
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults) result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                //预订方式
                results = (List)queryResults.getResults().get(0);
                roomInfo = (RoomInfo)queryResults.getResults().get(1);
               
//                //支付方式
//                paymentMethodsList = (List)queryResults.getResults().get(1);
//                //预订预览房间信息
//                bookingPreviewRoomsList = (List)queryResults.getResults().get(2);
//                bookOrderInfo = (BookOrderInfo)queryResults.getResults().get(3);
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 预修改
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-4-10上午10:31:40
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String toModOrderTablePeriod()
    {
        try
        {
            runLog.error("toModOrderTablePeriod");
            List conditionValueList = new ArrayList();
            
            conditionValueList.add(bookOrderInfo.getInnerIndex());
            conditionValueList.add(innerIndex);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            // 调用业务层获取一个路由对象
            Result result = bookOrderInfoService.queryOrderTablePeriods(queryConditon);
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults) result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                //预订方式
                results = (List)queryResults.getResults().get(0);
                tableNoInfo = (TableNoInfo)queryResults.getResults().get(1);
               
//                //支付方式
//                paymentMethodsList = (List)queryResults.getResults().get(1);
//                //预订预览房间信息
//                bookingPreviewRoomsList = (List)queryResults.getResults().get(2);
//                bookOrderInfo = (BookOrderInfo)queryResults.getResults().get(3);
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }

    /**
     * 
     * Description:修改客户预订信息
     * Implement: <br>
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-29下午4:07:53
     */
    public String doMod()
    {
        runLog.debug("doMod");

        try
        {
            // 调用业务层进行修改操作
            Result result = bookOrderInfoService.modOneBookOrder(bookOrderInfo, request);
            int resultCode = result.getResultCode();
            message = getText(Constants.MESSAGE_PREFIX + resultCode);
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                actResult = Constants.ACTRESULT_SUC;
                return SUCCESS;
            }
            else
            {
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }
        }
       
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 修改订单房间时段
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-4-12下午5:20:24
     */
    public String doModOrderRoomPeriod()
    {
        runLog.debug("doModOrderRoomPeriod");

        try
        {
          
            // 调用业务层进行修改操作
            Result result = bookOrderInfoService.modOneOrderRoomPeriod(bookOrderInfo,innerIndexs, request);
            int resultCode = result.getResultCode();
            message = getText(Constants.MESSAGE_PREFIX + resultCode);
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                actResult = Constants.ACTRESULT_SUC;
               
                return SUCCESS;
            }
            else
            {
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }
        }
       
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 修改订单桌次时段
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String 跳转标识
     * @author ozm2013-4-12下午5:20:24
     */
    public String doModOrderTablePeriod()
    {
        runLog.debug("doModOrderTablePeriod");

        try
        {
          
            // 调用业务层进行修改操作
            Result result = bookOrderInfoService.modOneOrderRoomPeriod(bookOrderInfo,innerIndexs, request);
            int resultCode = result.getResultCode();
            message = getText(Constants.MESSAGE_PREFIX + resultCode);
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                actResult = Constants.ACTRESULT_SUC;
               
                return SUCCESS;
            }
            else
            {
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }
        }
       
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 
     * Description: 删除预订方式
     * Implement: <br>
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-29下午4:10:40
     */
    public String doDel()
    {
        try
        {
            runLog.debug("doDel");
            // 调用业务层进行删除操作
            Result result = bookOrderInfoService.delBookOrders(innerIndexs, request);
            int resultCode = result.getResultCode();

            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                actResult = Constants.ACTRESULT_SUC;
                return SUCCESS;
            }
            // 如果删除中出现失败
            else
            {
                // 取得删除失败的条数
                int delErrorNum = result.getDelErrorNum();
                // 根据总条数和失败条数得出成功的条数
                int delSuccNum = innerIndexs.length - delErrorNum;
                // 定义国际化消息的参数
                String[] params = new String[]
                {
                    String.valueOf(delSuccNum), String.valueOf(delErrorNum)
                };
                message = getText(Constants.MESSAGE_PREFIX + resultCode,
                        params);
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 
     * Description: 删除预订时段
     * Implement: <br>
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-29下午4:10:40
     */
    public String doDelOrderPeriods()
    {
        try
        {
            runLog.debug("doDelOrderPeriods");
            
            List conditionValueList = new ArrayList();
          
//            roomNum = null == roomNum? "" : roomNum; 
//            tableNo =  null == tableNo? "" : tableNo;       
            conditionValueList.add(bookOrderInfo);
            conditionValueList.add(roomNum);
            conditionValueList.add(tableNo);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            // 调用业务层进行删除操作
            Result result = bookOrderInfoService.delOrderPeriods(queryConditon, request);
            int resultCode = result.getResultCode();

            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                actResult = Constants.ACTRESULT_SUC;
                return SUCCESS;
            }
            else
            {
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }
          
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    
    /**
     * 
     * Description: 新增Ajax校验
     * Implement: <br>
     * @return
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-31下午1:35:47
     */
    public String doCheckWhenAdd()
    {
        try
        {
            runLog.debug("doCheckWhenAdd");
            // 调用业务层进行删除操作
            Result result = bookOrderInfoService.checkContentWhenAdd(bookOrderInfo);
            int resultCode = result.getResultCode();

            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                customerInfo = (Customer)result.getResultPojo();           
                return SUCCESS;
            }
            else
            {
                return ERROR;
            }
            // 如果删除中出现失败
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
       
    }
    
   
   
  
    /**
     * 查询可预订房间
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String 
     * @author ozm2013-3-8上午10:14:00
     */
    public  String doQueryBookableRoom()
    {
        try
        {
            
            bookOrderInfo = new BookOrderInfo();
            //设置订单号
            bookOrderInfo.setOrderNum("" + new Timestamp(System.currentTimeMillis()));
            
            List<Object> conditionValueList = new ArrayList<Object>();
            conditionValueList.add(roomInfo.getRoomNum());
            conditionValueList.add(roomInfo.getRoomTypeInfo().getRoomTypeId());
            
            startTime = startTime == null ? new Timestamp(System.currentTimeMillis()) : startTime;
            endTime = endTime == null ? new Timestamp(System.currentTimeMillis() + 24 * 60 * 60 * 1000) : endTime;
            conditionValueList.add(startTime);
            conditionValueList.add(endTime);
            
            Result result = bookOrderInfoService.queryBookableRoomPeriod(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
                RoomPeriod roomPeriod = (RoomPeriod)results.get(0);
                roomInfo = roomPeriod.getRoomInfo();
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }

        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 
     * Description: 添加可以预订信息
     * Implement: <br>
     * @see
     * @return String 跳转标识
     * @author ozm2013-1-29下午3:37:58
     */
    public String doQueryRoomPeriod()
    {
        try
        {            
            createQueryRoomCondition();
            Result result = bookOrderInfoService.queryBookableRoomPeriod(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
//                periodResults = queryResults.getResults();
                results = queryResults.getResults();
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }

    }
    
    /**
     * 继续预订
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String 跳转标识
     * @author ozm2013-3-21上午10:18:50
     */
    public String toContinueBooking()
    {
        try
        {     
           
            savePeriodIndex();
            
            //标识已经存在预订记录
            session.put("hasRecord", 1); 
            
            return doQueryBookableRooms();
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
       
    }
    
    
    /**
     * 添加预订客户信息
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String 跳转标识
     * @author ozm2013-3-21上午10:18:50
     */
    @SuppressWarnings("rawtypes")
    public String toAddBookerInfo()
    {
        try
        {   
            savePeriodIndex();
            Result result = bookOrderInfoService.queryBookableOrderBysAndPayments();
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults) result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                //预订方式
                orderByList = (List)queryResults.getResults().get(0);
                //支付方式
                paymentMethodsList = (List)queryResults.getResults().get(1);
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
       
    }
    
    /**
     * 查询房间可预订桌次
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-3-21上午10:16:16
     */
    public String doQueryBookableTableNos()
    {
        try
        {
          
            createQueryTableCondition();
            Result result = bookOrderInfoService.queryBookableTableNos(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
//                periodResults = queryResults.getResults();
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 查询可预订房间
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-3-21上午10:16:16
     */
    public String doQueryBookableRooms()
    {
        try
        {
          
            createQueryRoomCondition();
            Result result = bookOrderInfoService.queryBookableRooms(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
//                periodResults = queryResults.getExResults();
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    
    /**
     * 查询房间可预订桌次时段
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-3-21上午10:16:16
     */
    public String doQueryBookableTablePeriods()
    {
        try
        {
          
            createQueryTableCondition();
            Result result = bookOrderInfoService.queryBookableTablePeriods(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
//                periodResults = queryResults.getExResults();
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 通过起止时间获取时段信息
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String 跳转标识
     * @author ozm2013-4-11下午5:24:48
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String doQueryPeriods()
    {
        try
        {
          
            List conditionValueList = new ArrayList();
            conditionValueList.add(startTime);
            conditionValueList.add(endTime);
            Integer roomId = roomInfo == null ? null : roomInfo.getInnerIndex();
            Integer tableId = tableNoInfo == null ? null : tableNoInfo.getInnerIndex();
            conditionValueList.add(roomId);
            conditionValueList.add(tableId);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            Result result = bookOrderInfoService.queryPeriods(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = (List)queryResults.getResults().get(0);
                if(null != roomId)
                {
                    roomInfo = (RoomInfo)queryResults.getResults().get(1);
                    // 跳转到分页页面
                    return SUCCESS;
                }
                else
                {
                    tableNoInfo = (TableNoInfo)queryResults.getResults().get(1);
                    return TABLEPERIOD;
                }
                         
               
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 预修改预订预览时间段
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-3-30下午10:58:25
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String toModPreviewPeriod()
    {
        try
        {
          
            List conditionValueList = new ArrayList();
            Set<Integer> roomPeriodset = (Set<Integer>)(null == session.get("roomPeriod")? null : session.get("roomPeriod"));
            Set<Integer> tablePeriodset = (Set<Integer>)(null == session.get("tablePeriod")? null : session.get("tablePeriod"));
//            roomNum = null == roomNum? "" : roomNum; 
//            tableNo =  null == tableNo? "" : tableNo;
           
            conditionValueList.add(roomPeriodset);
            conditionValueList.add(tablePeriodset);
            conditionValueList.add(roomNum);
            conditionValueList.add(tableNo);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            Result result = bookOrderInfoService.queryPreviewPeriods(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
//                periodResults = queryResults.getExResults();
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 删除预订预览时段
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-3-31上午8:25:41
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String delPreviewPeriod()
    {
        try
        {
          
            List conditionValueList = new ArrayList();
            Set<Integer> roomPeriodset = (Set<Integer>)(null == session.get("roomPeriod")? null : session.get("roomPeriod"));
            Set<Integer> tablePeriodset = (Set<Integer>)(null == session.get("tablePeriod")? null : session.get("tablePeriod"));
//            roomNum = null == roomNum? "" : roomNum; 
//            tableNo =  null == tableNo? "" : tableNo;
           
            conditionValueList.add(roomPeriodset);
            conditionValueList.add(tablePeriodset);
            conditionValueList.add(roomNum);
            conditionValueList.add(tableNo);
            queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
                    , null, null, conditionValueList);
            Result result = bookOrderInfoService.queryPreviewPeriods(queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
                
                for (int i= 0; i < results.size();i++)
                {
                    if(null == tableNo)
                    {
                        RoomPeriod roomPeriod = (RoomPeriod)results.get(i);
                        roomPeriodset.remove(roomPeriod.getInnerIndex());
                        
                    }
                    
                    if(null == roomNum)
                    {
                        TablePeriod tablePeriod = (TablePeriod)results.get(i);
                        tablePeriodset.remove(tablePeriod.getInnerIndex());
                    }
                    
                }
                
                if (null != roomPeriodset && roomPeriodset.size() > 0)
                {
                    session.put("roomPeriod", roomPeriodset);
                }
                
                if (null != tablePeriodset  && tablePeriodset.size() > 0)
                {
                    session.put("tablePeriod", tablePeriodset);
                }
                
                if (null != roomPeriodset && roomPeriodset.size() == 0)
                {
                    if (null == tablePeriodset ||(null != tablePeriodset   && tablePeriodset.size() == 0))
                    {
                        session.remove("hasRecord");
                        return SHOWTYPE;
                    }
                   
                    
                }
               if(null != tablePeriodset && tablePeriodset.size() == 0)
                {
                    if (null == roomPeriodset ||(null != roomPeriodset   && roomPeriodset.size() == 0))
                    {
                        session.remove("hasRecord");
                        return SHOWTYPE;
                    }
                }
               
               if (null == roomPeriodset  && null == roomPeriodset)
               {
                   session.remove("hasRecord");
                   return SHOWTYPE;
               }
                conditionValueList.clear();
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    
    /**
     * 取消预览订单信息
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author ozm2013-4-1下午1:48:17
     */
    public String doCancelPreviewOrder()
    {
        try
        {
           //清除缓存
           clearSession();
           return SUCCESS;
           
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 取消订单修改
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return Stirng
     * @author ozm2013-4-16下午2:22:32
     */
    public String doCancelModPeriod()
    {
        return SUCCESS;
    }
    
    /**
     * 创建查询条件
     * Description: <br>
     * Implement: <br>
     * @see
     * @return void
     * @author ozm2013-3-20下午4:59:11
     */
    private void createQueryTableCondition()
    {
        List<Object> conditionValueList = new ArrayList<Object>();
        roomNum = null == roomNum? "" : roomNum; 
        conditionValueList.add(roomNum);
        conditionValueList.add(tableNo);
        startTime = startTime == null ? new Timestamp(System.currentTimeMillis()) : startTime;
        endTime = endTime == null ? new Timestamp(System.currentTimeMillis() + 24 * 60 * 60 * 1000) : endTime;
        conditionValueList.add(startTime);
        conditionValueList.add(endTime);
        queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon
              , null, null, conditionValueList);
    }
    
    /**
     * 创建查询条件
     * Description: <br>
     * Implement: <br>
     * @see
     * @return void
     * @author ozm2013-3-20下午4:59:11
     */
    private void createQueryRoomCondition()
    {
        List<Object> conditionValueList = new ArrayList<Object>();
        roomNum = null == roomNum ? "" : roomNum;
        conditionValueList.add(roomNum);
        if ("".equals(roomNum))
        {
            conditionValueList.add(roomTypeId);
        }
        else
        {
            conditionValueList.add(null);
        }
        
        startTime = startTime == null ? new Timestamp(
                System.currentTimeMillis()) : startTime;
        endTime = endTime == null ? new Timestamp(System.currentTimeMillis()
                + 24 * 60 * 60 * 1000) : endTime;
        conditionValueList.add(startTime);
        conditionValueList.add(endTime);
        
        queryConditon = CommonUtil.createCompositeQueryCondition(queryConditon,
                null,
                null,
                conditionValueList);
    }
    
    
    
    /**
     * 将索引保存至session
     * Description: <br>
     * Implement: <br>
     * @param saveKey 保存关键子
     * @see
     * @return void
     * @author ozm2013-3-21上午11:01:28
     */
    @SuppressWarnings({"unchecked", "rawtypes"})
    private void savaIndexList(String saveKey)
    {
        if (null != innerIndexs)
        {
            Set<Integer> innerIndexSet = new HashSet(Arrays.asList(innerIndexs));
            //按照房间为单位预订
            if (null == session.get(saveKey))
            {
                session.put(saveKey, innerIndexSet);
            }
            else
            {
               
                Set<Integer> othersSet = (Set<Integer>)session.get(saveKey);
                othersSet.addAll(innerIndexSet);
                session.put(saveKey, othersSet);
            } 
        }
       
    }
    
    /**
     * 保存时段索引至session
     * Description: <br>
     * Implement: <br>
     * @see
     * @return void
     * @author ozm2013-3-28下午1:55:52
     */
    private void savePeriodIndex()
    {
        switch(roomTypeId)
        {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            {
                //房间为单位预订
                savaIndexList("roomPeriod");
                break;
            }
            case 6:
            case 7:
            {
                //按照桌子预订
                savaIndexList("tablePeriod");
                break;
            }
            default:break;
        }
    }
    
    /**
     * 清除Session
     * Description: <br>
     * Implement: <br>
     * @see
     * @return void
     * @author ozm2013-4-1下午2:13:20
     */
    private void clearSession()
    {
        //清除缓存
        session.remove("roomPeriod");
        session.remove("tablePeriod");
        session.remove("hasRecord");
    }
    
    /**
     * 获取系统HttpServletRequest实例
     */
    public void setServletRequest(HttpServletRequest request)
    {
        
        this.request = request;
    }
    
    /**
     * 获取session
     */
    public void setSession(Map<String, Object> session)
    {
        this.session = session;
        
    }
    
    public RunLog getRunLog()
    {
        return runLog;
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }


    public Page getPage()
    {
        return page;
    }

    public void setPage(Page page)
    {
        this.page = page;
    }

    public QueryCondition getQueryConditon()
    {
        return queryConditon;
    }

    public void setQueryConditon(QueryCondition queryConditon)
    {
        this.queryConditon = queryConditon;
    }

    public HttpServletRequest getRequest()
    {
        return request;
    }

    public void setRequest(HttpServletRequest request)
    {
        this.request = request;
    }
    
    @SuppressWarnings("rawtypes")
    public List getResults()
    {
        return results;
    }

    @SuppressWarnings("rawtypes")
    public void setResults(List results)
    {
        this.results = results;
    }

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }
    
    public Integer getActResult()
    {
        return actResult;
    }

    public void setActResult(Integer actResult)
    {
        this.actResult = actResult;
    }

    public Integer getInnerIndex()
    {
        return innerIndex;
    }

    public void setInnerIndex(Integer innerIndex)
    {
        this.innerIndex = innerIndex;
    }

    public Integer[] getInnerIndexs()
    {
        return innerIndexs;
    }

    public void setInnerIndexs(Integer[] innerIndexs)
    {
        this.innerIndexs = innerIndexs;
    }
    
    public BookOrderInfo getBookOrderInfo()
    {
        return bookOrderInfo;
    }

    public void setBookOrderInfo(BookOrderInfo bookOrderInfo)
    {
        this.bookOrderInfo = bookOrderInfo;
    }

    public BookOrderInfoService getBookOrderInfoService()
    {
        return bookOrderInfoService;
    }

    public void setBookOrderInfoService(BookOrderInfoService bookOrderInfoService)
    {
        this.bookOrderInfoService = bookOrderInfoService;
    }

    public Timestamp getStartTime()
    {
        return startTime;
    }

    public void setStartTime(Timestamp startTime)
    {
        this.startTime = startTime;
    }

    public Timestamp getEndTime()
    {
        return endTime;
    }

    public void setEndTime(Timestamp endTime)
    {
        this.endTime = endTime;
    }

    
    public Integer getRoomTypeId()
    {
        return roomTypeId;
    }

    public void setRoomTypeId(Integer roomTypeId)
    {
        this.roomTypeId = roomTypeId;
    }

    public RoomInfo getRoomInfo()
    {
        return roomInfo;
    }

    public void setRoomInfo(RoomInfo roomInfo)
    {
        this.roomInfo = roomInfo;
    }

   

    public String getRoomNum()
    {
        return roomNum;
    }

    public void setRoomNum(String roomNum)
    {
        this.roomNum = roomNum;
    }

    public String getTableNo()
    {
        return tableNo;
    }

    public void setTableNo(String tableNo)
    {
        this.tableNo = tableNo;
    }

    @SuppressWarnings("rawtypes")
    public List getOrderByList()
    {
        return orderByList;
    }

    @SuppressWarnings("rawtypes")
    public void setOrderByList(List orderByList)
    {
        this.orderByList = orderByList;
    }

    @SuppressWarnings("rawtypes")
    public List getPaymentMethodsList()
    {
        return paymentMethodsList;
    }

    @SuppressWarnings("rawtypes")
    public void setPaymentMethodsList(List paymentMethodsList)
    {
        this.paymentMethodsList = paymentMethodsList;
    }

    @SuppressWarnings("rawtypes")
    public List getBookingPreviewRoomsList()
    {
        return bookingPreviewRoomsList;
    }

    @SuppressWarnings("rawtypes")
    public void setBookingPreviewRoomsList(List bookingPreviewRoomsList)
    {
        this.bookingPreviewRoomsList = bookingPreviewRoomsList;
    }

    public TableNoInfo getTableNoInfo()
    {
        return tableNoInfo;
    }

    public void setTableNoInfo(TableNoInfo tableNoInfo)
    {
        this.tableNoInfo = tableNoInfo;
    }

   
}
